package agents;

import java.awt.Point;
import java.io.IOException;
import java.util.Random;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import jade.lang.acl.ACLMessage;
import logic.Map;


/**
 * 
 * @author tomek
 *   
 */
public class RandomlyWalkingAgent extends Agent {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6818791548263534572L;
	Random r = new Random(System.currentTimeMillis());
	int x = Math.abs(r.nextInt()%100);
	int y = Math.abs(r.nextInt()%100);

	@Override
	protected void setup() {
		super.setup();
		addBehaviour(new TickerBehaviour(this, 500) {

			@Override
			protected void onTick() {
				ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
				msg.addReceiver(new AID("Mapa", AID.ISLOCALNAME));

				if(r.nextInt()%2 == 0)
					x++;
				else if(r.nextInt()%3 == 0)
					x--;
					
				if(r.nextInt()%3 == 0)
					y++;
				else if(r.nextInt()%2 == 0)
					y--;
					
					
				
				try {
					msg.setContentObject(new Point(x, y));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				send(msg);
			}
		});
	}

}
